package com.sykj.controller;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.sykj.bean.Book;
import com.sykj.bean.Flight;
import com.sykj.service.BookService;
import com.sykj.service.FlightService;

@RestController
@RequestMapping("/flight")
public class FlightController {
	/**
	 * 单表显示图书信息
	 */
	@Autowired
	private FlightService flightService;
	/**
	 * 查询所有航班API
	 * @return
	 */
	/*@RequestMapping("/queryFlights")
	public List<Flight> queryFlights(){		
		return flightService.queryFlights();
	}*/
	
	@RequestMapping("/queryFlights_zhcx")
	public List<Flight> queryFlights_zhcx(Flight flight){		
		return flightService.queryFlights_zhcx(flight);
	}
	
	@RequestMapping("/saveFlight")
	public Map saveFlight(Flight flight){		
		 flightService.save(flight);
		 
		 Map map=new HashMap();
		 map.put("state","ok");
		 return map;
	}
	@RequestMapping("/deleteFlight/{flightID}")
	public Map deleteFlight(@PathVariable("flightID") Integer flightID){		
		 flightService.removeById(flightID);		 
		 Map map=new HashMap();
		 map.put("state","ok");
		 return map;
	}
	
	
	/*@RequestMapping("/batchDelete")
	public Map batchDelete(String ids){	 //批量删除  字符串接收	
		 String flightID[]=ids.split(",");
		 List idList=Arrays.asList(flightID);
		 
		 flightService.removeByIds(idList);//批量删除
		 Map map=new HashMap();
		 map.put("state","ok");
		 return map;
	}
	*/
	/*@RequestMapping("/batchDelete")  //数组 批量删除
	public Map batchDelete(@RequestParam(value = "ids[]")  Integer[] ids){		
		// String flightID[]=ids.split(",");
		 List idList=Arrays.asList(ids);
		 System.out.println("---");
		 flightService.removeByIds(idList);//批量删除
		 Map map=new HashMap();
		 map.put("state","ok");
		 return map;
	}
	*/
	@RequestMapping("/batchDelete")  //数组 批量删除
	public Map batchDelete(@RequestBody  List<Integer> ids){		
		// String flightID[]=ids.split(",");
		// List idList=Arrays.asList(ids);
		 System.out.println("---");
		 flightService.removeByIds(ids);//批量删除
		 Map map=new HashMap();
		 map.put("state","ok");
		 return map;
	}
}
